#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by master on 2017/3/13



from urllib import request
import zlib

req = request.Request("https://zhihu.com")
req.add_header('User-Agent',
               'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 UBrowser/5.5.9703.2 Safari/537.36')
req.add_header('Accept-encoding', 'gzip')
with request.urlopen(req) as response:
    gzipd = response.headers.get('Content-Encoding')
    if gzipd == 'gzip':
        data = zlib.decompress(response.read(), 16 + zlib.MAX_WBITS)

    else:
        data = response.read()
print(data)
